package top.kaoshanji.p2ch08a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import top.kaoshanji.u1constant.FileConstant;

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 代码清单-p2ch08a-01-250页a：在程序中使用javac工具编译Java源代码
 * author kaoshanji
 * ^_^
 * create time 2025/1/21 18:54
 */
public class JavacExample01 {

    private static final Logger logger = LogManager.getLogger(JavacExample01.class);

    public static void main(String[] args) throws IOException {
        logger.info("...代码清单-p2ch08a-01-250页a：在程序中使用javac工具编译Java源代码...");

        // 输入的Java源代码的路径
        Path src = Paths.get(FileConstant.LOCAL_ROOT_PATH.concat("Hellop2ch08a01.java"));
        // 编译之后产生的class文件的输出路径
        Path output = Paths.get(FileConstant.LOCAL_ROOT_PATH);

        ProcessBuilder pb = new ProcessBuilder("javac.exe", src.toString(), "-d", output.toString());

        pb.start();

    }

}
